<?php
// test-real-url.php
define('WP_USE_THEMES', false);
require_once('wp-load.php');

// 测试URL提取
$test_full_url = 'http://8.130.173.191/新闻聚焦/news-detail/?news_url=https://mini.eastday.com/mobile/250901134223924812293.html';
$test_news_url = 'https://mini.eastday.com/mobile/250901134223924812293.html';

echo "<h2>URL提取测试</h2>";
echo "<p>完整URL: " . htmlspecialchars($test_full_url) . "</p>";
echo "<p>提取的新闻URL: " . htmlspecialchars($test_news_url) . "</p>";

// 测试数据库查询
$db_config = [
    'host' => 'localhost',
    'user' => 'wordpress',
    'password' => '9f172735e1037be2',
    'database' => 'wordpress',
    'table' => 'NEWSLIST'
];

$conn = new mysqli($db_config['host'], $db_config['user'], $db_config['password'], $db_config['database']);

if ($conn->connect_error) {
    die("数据库连接失败: " . $conn->connect_error);
}

// 测试真正的新闻URL
$stmt = $conn->prepare("SELECT title, url FROM NEWSLIST WHERE url = ?");
$stmt->bind_param("s", $test_news_url);
$stmt->execute();
$result = $stmt->get_result();

echo "<h3>数据库查询结果:</h3>";
if ($result && $result->num_rows > 0) {
    $row = $result->fetch_assoc();
    echo "<p>✅ 找到匹配记录:</p>";
    echo "<p>标题: " . htmlspecialchars($row['title']) . "</p>";
    echo "<p>URL: " . htmlspecialchars($row['url']) . "</p>";
} else {
    echo "<p>❌ 未找到匹配记录</p>";
    
    // 显示数据库中的一些URL以供参考
    $all_urls = $conn->query("SELECT url, title FROM NEWSLIST LIMIT 5");
    echo "<p>数据库中的示例URL:</p>";
    while ($url_row = $all_urls->fetch_assoc()) {
        echo "<p>" . htmlspecialchars($url_row['url']) . " - " . htmlspecialchars($url_row['title']) . "</p>";
    }
}

$stmt->close();
$conn->close();
?>